#include <iostream>
#include <string>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;

int minimumTotal(vector<vector<int> >& triangle) {
    int m = triangle.size();
    int dp[m][m];
    //dp[i][i]：从第一行达到 第i+1行的第i+1个元素的距离
    //每一行除了第一个元素和最后一个元素，有俩中方法从上一行到达这一行。
    dp[0][0] = triangle[0][0];
    for (int i = 1; i < m; i++) { 
        //初始化每行一个元素的距离值
        dp[i][0] = dp[i-1][0] + triangle[i][0];
        //初始化每一行最后一个元素的距离值
        dp[i][i] = dp[i-1][i-1] + triangle[i][i];
    }
    if (m < 3){
        return *min_element(dp[m-1], dp[m-1] + m); 
    } 
    for (int i = 2; i < m; i++) {
        //i代表行数
        for (int j = 1; j < i; j++) {
            dp[i][j] = min(dp[i-1][j-1], dp[i-1][j]) + triangle[i][j];
        }
    }
    return *min_element(dp[m-1], dp[m-1] + m); 
    
}
int main(){
    int height;
    cin >> height;
    int num = height * (height + 1) / 2;

    vector<vector<int> > triangle;
    int row = 1;

    for (int i = 0; i < height; i++) {
        vector<int> nums(row);
        for (int j = 0; j < row; j++) {
            cin >> nums[j];
        }
        row += 1;
        triangle.push_back(nums);
    }
    cout << minimumTotal(triangle) << endl;

    return 0;
}